#ifndef OTHERTMD_H_
#define OTHERTMD_H_

#include <vector>
#include "ShowfindupdateTMD.h"

bool is_prods(int prods_id, vector<Product> prods)
{
  int i;
  for(i=0; i < prods.size(); ++i)
  {
    if(prods_id == prods[i].id_get())
	{
	  return true;
	}
  }
  return false;
}

class OtherTMD
{
  public:
    static void delete_product(vector<Product> &prods)
    {
      cout << "Enter the product ID of the product you want to delete:";
	  int id=0;
	  while(!(cin >> id) || !(is_prods(id, prods)))
	  {
	    cerr << "Invalid product ID try agian:";
	    cin.clear();
	    cin.ignore();
	  }
	  int i;
	  for(i=0; i<prods.size(); ++i)
	  {
	    if(prods[i].id_get()==id)
	    {
	      prods.erase(prods.begin()+i);
	    }
	  }
    }
    static void change_price(vector<Product> &prods)
    {
      cout << "Enter the product ID of the product whose price you want to change:";
	  int id;
	  while(!(cin >> id) || !(is_prods(id, prods)))
	  {
	    cerr << "Invalid product ID try agian:";
	    cin.clear();
	    cin.ignore();
	  }
	  cout << "Enter the new price of product with ID " << id << " :";
	  double price;
	  while(!(cin >> price) || !(ShowfindupdateTMD::two_digits(price)))
	  {
	    cout << "You did not enter a double for the price. Try Again!" << endl;
	    cout << "Or you entered a number with more than 2 digits for the price. Try Again!" << endl;
	    cin.clear();
	    cin.ignore();
	    cout << "Enter the new price of product with ID " << id << " :";
	  }
	  string name;
	  int cat_id;
	  int i;
	  for(i=0; i<prods.size(); ++i)
	  {
	    if(prods[i].id_get()==id)
	    {
	      name = prods[i].name_get();
		  cat_id = prods[i].cat_get();
	      prods.erase(prods.begin()+i);
		  prods.push_back(Product(id, cat_id, name, price));
	    }
	  }
    }
    static void add_category(vector<Category> &cats)
    {
      cout << "Enter the new category name you want to add:";
	  string name;
	  cin >> name;
	  cout << "Enter the 4 digit category ID for " << name << " below.";
      cout << "If there is less than 4 digits, the computer will simply add leading zeros:";
	  int id;
	  while(!(cin >> id) || ShowfindupdateTMD::digits(id) > 4 || ShowfindupdateTMD::is_cat(id, cats))
	  {
	    cout << "Invalid product ID. Either you didn't enter a decimal number," << endl;
	    cout << "you enterad a number with more than 4 digits," << endl;
	    cout << "or you entered an already existing category number. Try Again!" << endl;
	    cin.clear();
	    cin.ignore();
	    cout << "Enter the 4 digit category number of " << name << ":";
	    id = 0;
	  }
	  cats.push_back(Category(id, name));
    }
};

#endif  //OTHERTMD_H_
